package com.hdculture.simple.expensemanager.premium;

import com.hdculture.simple.expensemanager.premium.R;

import android.app.Activity;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import android.view.*;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
/*
 * This is a multi-purpose class. By passing extra boolean value ISINCOME the behaviour can be changed.
 *  
 */
public class MonthSelector extends Activity {
	EditText yearText, monthText;
	Button continueButton, backButton;
	boolean income=true;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.monthselector);
        Intent i = getIntent();
        Bundle b = i.getExtras();
        income=b.getBoolean("ISINCOME");
        
        monthText = (EditText)findViewById(R.id.monthText);
        yearText = (EditText)findViewById(R.id.yearText);
        backButton = (Button)findViewById(R.id.backButton);
        backButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
        continueButton = (Button)findViewById(R.id.continueButton);
        continueButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				String yearStr=yearText.getText().toString(),monthStr=monthText.getText().toString();
				if(yearStr.length()==4 && monthStr.length()<=2 && monthStr.length()!=0){
					int year=0, month=0;
					year=Integer.parseInt(yearStr);
					month=Integer.parseInt(monthStr);
					if(income==true){
						Intent i = new Intent(MonthSelector.this,MonthIncomeActivity.class);
						i.putExtra("MONTH", month);
						i.putExtra("YEAR", year);
						startActivity(i);
					}else{
						Intent i = new Intent(MonthSelector.this,MonthExpenseActivity.class);
						i.putExtra("MONTH", month);
						i.putExtra("YEAR", year);
						startActivity(i);
					}
				}else{
					Toast.makeText(MonthSelector.this, "Please type full year name. For instance year as 2011 and month as 9.", 1000).show();
				}
			}
		});
    }
}